<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 会员实名认证
 */
class Usersmrz extends Common
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';
    protected $userModel = null;
    protected $usersmrzModel = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->usersmrzModel = new \app\admin\model\UserSmrz();
        $this->userModel = new \app\admin\model\User();
    }

    /**
     * 会员实名认证
     */
    public function getusersmrzeit()
    {
        $id=$this->request->request('id');
        $username = $this->request->request('username');
        $mobile = $this->request->request('mobile');
        $gllx = $this->request->request('gllx');
        $dawe = $this->request->request('dawe');
        $bume = $this->request->request('bume');
        $zzfg = $this->request->request('zzfg');
        $image = $this->request->request('image');
        $fwid = $this->request->request('fwid');
        $group_id = $this->request->request('group_id');
        if(!is_numeric($id)){
            $this->outputError('参数错误');
        }
        $User=$this->userModel->where('id',$id)->find();
        if(!$User){
            $this->outputError('用户不存在');
        }

        $re = Db('fwxx')
            ->where('id',$fwid)
            ->update(['uid'=>$id]);
            $data=['uid'=>$id,'gllx'=>$gllx,'dawe'=>$dawe,'bume'=>$bume,'zzfg'=>$zzfg,'image'=>$image,'username'=>$username,'mobile'=>$mobile];
            //判断用户实名认证记录是否存在
            $smrzInfo=Db('user_smrz')->where('uid',$id)->find();
            if($smrzInfo){
                $data['status']=0;
                $res=   Db('user_smrz')->where('uid',$id)->update($data);
            }else {
                $res = $this->usersmrzModel
                    ->insert($data);
            }
            if($res){
                $UserInfo=$this->userModel->where('id',$id)->find();
//                $smrz=Db('user_smrz')->where('uid',$UserInfo['id'])->find();
////        $data=['gllx'=>$smrz['gllx'],'dawe'=>$dawe,'bume'=>$bume,'zzfg'=>$zzfg,'image'=>$image];
//                $UserInfo['gllx']=$smrz['gllx'];
//                $UserInfo['dawe']=$smrz['dawe'];
//                $UserInfo['bume']=$smrz['bume'];
//                $UserInfo['zzfg']=$smrz['zzfg'];
//                $UserInfo['image']=$smrz['image'];
                $this->outputData($UserInfo);
            }else{
                $this->outputData('提交失败');
            }

    }

}
